<?php
require_once '../conf.php';
require_once PATH_TO_SOURCE.'/model/model.php';
require_once PATH_TO_SOURCE.'/controller/controller.php';






	$name = $_GET['url'];

	$p = new product(null,null,$name);
	$kcal = $p->getCalories();
	$burns = $p->getFreeBurnCalories();
	
	

?>


	<div class="services-page main grid-wrap">

		<header class="grid col-full">
			<hr>
			<p class="fleft"><?php echo "kalorie ".strtolower($p->getName()) ; ?></p>
		</header>
    
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          [ '' ,'Czas'],
          
          <?php 	
          
 
          
          	$max=count($burns);
          	
      
          	
          	for($i=0;$i<$max;$i++){
          		
            
			$burns[$i][time]=$kcal/$burns[$i]['kg60']*60;
			
			
			if($i==($max-1)){
				echo "['".$burns[$i]['name']."',".round($burns[$i]['time'],0)."]]";
				break;
			}
			
			echo "['".$burns[$i]['name']."',".round($burns[$i]['time'],0)."],";
          	}
		?>);

        var options = {
          title: 'Ile czasu (min) potrzeba na spalenie 100g/100ml <?php echo strtolower($p->getName()); ?>.',
          series: [{color: '#9CA0A6', visibleInLegend: false},{}, {}, {color: 'red', visibleInLegend: false},{}]        };

        var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }

      google.load('visualization', '1', {packages:['table']});
      google.setOnLoadCallback(drawTable);
      function drawTable() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Tabela kalorii');
        data.addColumn('number', 'Ilość');
        
        data.addRows([
          <?php echo "['Kalorie', {v:".$p->getCalories()."}],"?>
          <?php echo "['Węglowodany', {v:".$p->getCarbon()."}],"?>
          <?php echo "['Tłuszcz', {v:".$p->getFat()."}],"?>
          <?php echo "['Białko', {v:".$p->getProtein()."}]"?>
          
        ]);

        var table = new google.visualization.Table(document.getElementById('table_div'));
        table.draw(data, {showRowNumber: true});
      }

      </script>
      
      
      
      <h1><?php echo $p->getName();?></h1>
      	
      	<h2> Czy zastawiałeś się kiedyś ile kalorii ma <?php echo $p->getName();?> ?</h2>
<div class="charts">

	<div id='table_div' style="width: 300px; height: 150px; float:left; ; margin-top:37px;"></div>
	<div id="chart_div" style="width: 800px; height: 500px;float:right;"></div>
</div>
	
</div>